package com.elinkway.infinitemovies.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * 广告统计 类
 *
 * @author zhangshuo
 */
public class AdStatisticsSp {

    private final static String ADDATA_SP_NAME = "addata";

    public final static String BAIDUSPLASHADRESPONSE = "baidusplashadresponse";
    public final static String BAIDUSPLASHADREQUEST = "baidusplashadrequest";
    public final static String BAIDUSPLASHADSUCCESS = "baidusplashadsuccess";
    public final static String BAIDUSPLASHADERROR = "baidusplashaderror";
    public final static String BAIDUSPLASHADSHOW = "baidusplashadshow";

    public final static String BAIDUEXITADRESPONSE = "baiduexitadresponse";
    public final static String BAIDUEXITADREQUEST = "baiduexitadrequest";
    public final static String BAIDUEXITADSUCCESS = "baiduexitadsuccess";
    public final static String BAIDUEXITADERROR = "baiduexitaderror";
    public final static String BAIDUEXITADSHOW = "baiduexitadshow";

    public static void saveVaule(Context context, String key, long value) {
        SharedPreferences sp = context.getSharedPreferences(ADDATA_SP_NAME, Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putLong(key, value);
        editor.commit();
    }

    public static long getVaule(Context context, String key) {
        return getVaule(context, key, 0);
    }

    private static long getVaule(Context context, String key, long defValue) {
        long flag = 0;
        try {
            SharedPreferences sp = context.getSharedPreferences(ADDATA_SP_NAME, Context.MODE_PRIVATE);
            flag = sp.getLong(key, defValue);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    public static void savaOneUp(Context context, String key){
        long nowValue = getVaule(context, key);
        nowValue++;
        saveVaule(context, key, nowValue);
    }

}
